package service;

import mapper.ResourceStrategyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.ResourceStrategy;
import po.Result;

import java.util.List;

@Service
public class ResourceStrategyServiceImpl implements ResourceStrategyService {
    @Autowired
    private ResourceStrategyMapper resourceStrategyMapper;

    @Override
    public List<ResourceStrategy> findAllResourceStrategies() throws Exception {
        return resourceStrategyMapper.findAllResourceStrategies();
    }

    @Override
    public Result addResourceStrategy(ResourceStrategy resourceStrategy) {
        Result result = new Result();
        try {
            resourceStrategyMapper.addResourceStrategy(resourceStrategy);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteResourceStrategyById(int id) {
        Result result = new Result();
        try {
            resourceStrategyMapper.deleteResourceStrategyById(id);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public Result updateResourceStrategyById(int id, ResourceStrategy resourceStrategy) {
        Result result = new Result();
        try {
            resourceStrategy.setId(id);
            resourceStrategyMapper.updateResourceStrategyById(resourceStrategy);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("修改失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("修改成功！");
        return result;
    }
}
